Understanding Width, Height, Padding, and Border in the Box Model
In the CSS box model, the width and height properties define the size of the content box by default. The total visible size of an element also includes padding, borders, and margins around that content area.
Content box: The area where text and other content appear. Controlled by width and height.
Padding: The space between the content and the border. Increases total element size.
Border: The outline around the padding and content.
Margin: The space outside the border, separating the element from others.
With the default content-box, the specified width and height apply only to the content area. Padding and border add to the total rendered size.
With box-sizing: border-box, the width and height include the content, padding, and border. This makes sizing more predictable and easier to manage in responsive layouts.
content-box (default): Width and height apply only to content; padding and border increase total size.
border-box: Width and height include padding and border; total size stays fixed.
Margins are always outside the box and do not affect element width or height.